package com.linsen.core.common.enums;

import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonValue;
import lombok.AllArgsConstructor;
import lombok.Getter;

import java.util.HashMap;
import java.util.Map;

@Getter
@AllArgsConstructor
public enum YnType {
    NO(0, "否"),
    YES(1, "是"),
    ;

    @JsonValue
    private final Integer value;
    private final String desc;

    private static final Map<Integer, YnType> VALUES = new HashMap<>();

    static {
        for (final YnType ynType : YnType.values()) {
            YnType.VALUES.put(ynType.getValue(), ynType);
        }
    }

    @JsonCreator
    public static YnType getByValue(Integer value) {
        return YnType.VALUES.get(value);
    }
}
